package com.example.fragment;

import com.example.activity.MyLoginActivity;
import com.example.dianping.R;
import com.example.utils.MyUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class FragmentMy extends Fragment implements OnClickListener {
	@ViewInject(R.id.to_login_btn)
	Button loginImage;

	@ViewInject(R.id.textView1)
	TextView loginText;
	
	@ViewInject(R.id.imageView5)
	ImageView loginImage2;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.fragment_my, null);
		ViewUtils.inject(this, view);

		loginText.setOnClickListener(this);
		loginImage.setOnClickListener(this);
		return view;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.to_login_btn:
		case R.id.textView1:
			login();
			break;

		default:
			break;
		}
	}

	private void login() {
		Intent intent = new Intent(getActivity(), MyLoginActivity.class);
		startActivityForResult(intent, MyUtils.RequestLoginCode);

	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);

		if (requestCode == MyUtils.RequestLoginCode
				&& resultCode == MyUtils.RequestLoginCode) {
			loginText.setText(data.getStringExtra("username"));
			loginImage2.setImageResource(R.drawable.ic_tab_songs_selected);
		}
	}
}
